package com.itheima.sfbx.insurance.handler.impl;

import com.itheima.sfbx.insurance.dto.DoInsureVo;
import com.itheima.sfbx.insurance.handler.InsureHandler;
import com.itheima.sfbx.insurance.pojo.CustomerRelation;
import com.itheima.sfbx.insurance.service.ICustomerRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @ClassName AccidentInsureHandler.java
 * @Description 保障型意外类：保险投保、创建订单、保费计算
 */
@Service
public class AccidentInsureHandler extends SafeguardInsureHandler implements InsureHandler {
    @Autowired
    private ICustomerRelationService customerRelationService;
    @Override
    public String doPremium(DoInsureVo doInsureVo) {
        String customerId = doInsureVo.getCustomerRelationIds().get(0);
        CustomerRelation relation = customerRelationService.getById(customerId);
        if (relation!=null){
            BigDecimal income = relation.getIncome();
            if (income==null||income.compareTo(new BigDecimal("100000"))>0){
                throw new RuntimeException("杀手");
            }
        }
        return super.doPremium(doInsureVo);
    }

}
